<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
/**
 * 
 * @author 时
 * 基控制器(所有的控制器都要继承这个控制器)(包括权限的查询)
 *
 */
class Common extends Controller
{
    public function _empty($name){
        return $this->showCity($name);
    }
    protected function showCity($name){
        return view('');
    }
    public function _initialize()
    {
        //这里初始化看用户是否正常登陆
        $cookie=cookie('study_admin_info');//cookie中取出相应的值
        $username=input('session.userinfo.username');
       if(isset($cookie)&&!isset($username))
       {
          session('userinfo',$cookie); 
       }
       $username=input('session.userinfo.username');
        if(!isset($username))
        {
          $this->redirect('admin/admin/index');
        }else {
            //取出用户的ID 根据用户ID 进行连表查询出用户的权限 
           //视图查询
           //$admin_id=$session['admin_id'];
          //$this->redirect('admin/rom/show');
          //超级管理员就不要进行权限过滤 对登录名不为admin进行权限过滤
          if(input('session.userinfo.username')!=='admin')
          {
           $request=request();
           $mname=$request->controller();
           $aname=$request->action();
           $nodelist=Session::get('admin.nodelist');
              if(empty($nodelist[$mname])|| !in_array($aname,$nodelist[$mname]))
              {
                  $this->error("抱歉！没有操作权限!");//没有权限跳转没有权限页面
                  exit;
                 
              }
          }
        }
    }
}